from flask import Flask,jsonify,request
#导入配置文件
from config import Config
from db import db1
import json
app = Flask(__name__)
#加载配置文件
app.config.from_object(Config)
#跨域配置
from flask_cors import CORS
CORS(app)
#测试添加展示
@app.route('/test')
def test():
    sql1 = "select * from test values(0,'txt')"
    db1.update(sql1)
    sql = "select * from test"
    res = db1.find_all(sql)
    return jsonify({'list':res})

@app.route('/course',methods=['POST'])
def testM():
    #接收客户传递的参数
    data = request.data
    if data:
        data = json.loads(data)
    else:
        data = request.form
        course = test(name=data['name'],can=data['can'])
        #添加
        db1.session.add(course)
    #提交
    db1.session.commit()
    #返回
    return jsonify({'code':200})

if __name__ == "__main__":
    app.run(debug=True)